package org.yufan.message;

import org.apache.activemq.command.ActiveMQTextMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.yufan.controller.ItemController;
import org.yufan.service.JedisService;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;

public class CustomerMessageListener implements MessageListener {
    private Logger LOGGER=LoggerFactory.getLogger(CustomerMessageListener.class);
    @Autowired
    private JedisService jedisService;
    @Override
    public void onMessage(Message message) {

        ActiveMQTextMessage am= (ActiveMQTextMessage) message;

        try {
            String itemId=am.getText();
             LOGGER.info("front接收到消息队列的消息{}",itemId);

             //移除缓存
            jedisService.del(ItemController.ITEM_CACHE+itemId);
            LOGGER.info("删除了{}商品的缓存------------------------",itemId);

        } catch (JMSException e) {
            e.printStackTrace();
        }


    }


}
